package cloudbus

import (
	"zstackgo/pkg/header"
	"zstackgo/pkg/header/errorcode"
	"zstackgo/pkg/header/message"
)

const (
	HEADER_NO_NEED_REPLY_MSG = "noReply"
	HEADER_CORRELATION_ID    = "correlationId"
	HEADER_REPLY_TO          = "replyTo"
	HEADER_IS_MESSAGE_REPLY  = "isReply"
	HEADER_MESSAGE_META_DATA = "metaData"
	HEADER_DEAD_LETTER       = "dead-message"
	HEADER_TASK_STACK        = "task-stack"
	HEADER_TASK_CONTEXT      = "task-context"
	HEADER_SCHEMA            = "schema"
)

// 只需要注册你的Service，使用CloudBus指定Service发送，Service就能收到，如果你需要注册你的CallBack，也能很简单完成
// 在ZStack的每个Component启动时，会向CloudBus订阅event。当CloudBus收到需要publish的event，会向所有实现CloudBusEventListener接口的对象发送事件，由他们自己选择是否处理这些事件
type CloudBus interface {
	header.Component
	Send(msg message.Message)
	Sends(msgs []message.Message)
	SendNeedReply(msg message.NeedReplyMessage, callback CloudBusCallBack)
	SendNeedRepliesWithParallel(msgs []message.NeedReplyMessage, parallelLevel int, callBack CloudBusListCallBack)
	Route(msg message.Message)
	Routes(msgs []message.Message)
	Reply(request message.Message, reply *message.MessageReply)
	Cancel(correlationId string, err string)
	Publish(event message.Event)
	Publishs(events []message.Event)
	Call(msg message.NeedReplyMessage) *message.MessageReply
	Calls(msgs []message.NeedReplyMessage) []*message.MessageReply
	RegisterService(serv header.Service) error
	UnregisterService(serv header.Service)
	SubscribeEvent(listener CloudBusEventListener, events ...message.Event) EventSubscriberReceipt
	DealWithUnknowMessage(msg message.Message)
	//ReplayErrorByMessageType(msg message.Message, e error)
	//ReplayErrorByMessageTypeS(msg message.Message, e string)
	ReplayErrorByMessageType(msg message.Message, e *errorcode.ErrorCode)
	// LogExceptionWithMessageDump(msg message.Message) error
	GetServiceId(tartgetServiceId string) string
	MakeLocalServiceId(serviceId string) string // 如ZStack的伸缩性秘密武器：无状态服务中所说一般，每个管理节点都会注册一堆服务队列。因此我们要按照其格式组装，这样消息才能被服务所接收
	MakeLocalServiceIdMsg(msg message.Message, serviceId string)
	MakeServiceIdByManagementNodeId(serviceId, managementNodeId string) string
	MakeServiceIdByManagementNodeIdMsg(msg message.Message, serviceId, managementNodeId string)
	MakeTargetServiceIdByResourceUuid(serviceId, resouceUuid string) string // 在ZStack中，ManagerNode很有可能是集群部署的，每个MN管控不同的资源。那么就需要一致性哈希环来确定资源所在哪个MN
	MakeTargetServiceIdByResourceUuidMsg(msg message.Message, serviceId, resouceUuid string)
	InstallBeforeDeliveryMessageInterceptor(interceptor message.BeforeDeliveryMessageInterceptor, classes ...message.Message)
	//InstallBeforeDeliveryMessageInterceptors(interceptor message.BeforeDeliveryMessageInterceptor, classes []message.Message)
	InstallBeforeSendMessageInterceptor(interceptor message.BeforeSendMessageInterceptor, classes ...message.Message)
	InstallBeforePublishEventInterceptor(interceptor message.BeforePublishEventInterceptor, classes ...message.Event)
}

func DefaultHandleHttpRequest() error {
	return nil
}

func DefaultGetEnvelopeSize() int {
	return 0
}
